<?php
class Control_Data_setPlatformData {

	function setPlatformData($game, $type = "") {
		$gameEn = $game;
		$url = MooConfig::get('main.url.fetch_game');
		$channel_lang = MooConfig::get("channel_lang.{$game}.en_zh");
		$result = MooUtil::curl_send($url);
		$resultArr = MooJson::decode($result, true);
		$gameConf = array();
		if ($resultArr) {
			foreach ($resultArr as $key => $val) {
				$gameConf[$val['game']]['platform'] = explode(',', $val['platform']);
				$gameConf[$val['game']]['channel'] 	= explode(',', $val['channel']);
			}
		}
		
		$userName = MooObj::get('User')->getUserName();
		$channelLimit = MooConfig::get('channel_limit');
		if(!empty($channelLimit[$game][$userName])) {
			$platformInfo = $channelLimit[$game][$userName];
		} else {
			$platformInfo = $gameConf[$game];
		}
		
		$gameLangConf = MooConfig::get('game_lang.en_zh');
		if($gameLangConf[$game]) {
			$game = $gameLangConf[$game];
		}
		
		MooView::set('nowGame', $game);
		MooView::set('platforms', $platformInfo['platform']);

		$channels  = $platformInfo['channel'];
		// 中英翻译
		foreach($channels as $k => $v) {
			if($channel_lang[$v]) {
				$channels[$k]  = $channel_lang[$v];
			}
		}
		
		// callback覆盖掉
		if($type == "callback") {
			
			$channel_lang = MooConfig::get("callbackchannel_lang.{$gameEn}.en_zh");
			$channels = array();
			foreach($channel_lang as $key => $val) {
				$channels[] = $val;
			}
		}
		
		MooView::set('channels', $channels);
	}
}
